home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 1 / PC Actual CD 01.iso / share / dos / demos / planets / source.lzh / GUSHCODE.ASM next >
Encoding:
Assembly Source File  |  1994-05-01  |  5.1 KB  |  221 lines

  1.  
  2. ;
  3. ;   GUSHCODE.ASM
  4. ;
  5. ;   (Simon Hern, 1994)
  6. ;
  7. ;   Assembler routine for executing the gush code of a planet
  8. ;
  9. ;   The 'gush' is a large chunk of code which, when executed, draws a planet
  10. ;   It is split into four 'slices' to work with the 'planes' in Mode X
  11. ;   The first byte of the gush is the radius of the planet (not needed here)
  12. ;   This is followed by four jump instructions, vectors into the four slices
  13. ;   A slice is called with ds:si pointing to the 'xion' surface data
  14. ;                      and es:di pointing to the destination in video memory
  15. ;   Each slice ends with a 'far' return
  16. ;   This routine is an interface to the gush code
  17. ;   It matches the gush slices to the Mode X planes
  18. ;
  19. ;   Uses 320x240 Mode X (as supported by XLib06)
  20. ;
  21. ;   Called from PLANETS.C
  22. ;
  23.  
  24.  
  25.     public _display_gush            ; Exported routine
  26.  
  27.     extrn _HiddenPageOffs:word      ; Offset of destination video page
  28.                                     ; (variable provided by XLib)
  29.  
  30.  
  31. SEQU_ADDR   EQU 003c4h      ; Base port of the Sequencer (ModeX plane select)
  32. VID_SEG     EQU 0a000h      ; Segment of video memory
  33. SCR_WIDTH   EQU 320         ; Screen width (Mode X)
  34. SCR_HEIGHT  EQU 240         ; Screen height (Mode X)
  35.  
  36.  
  37. _Text   SEGMENT BYTE PUBLIC 'Code'
  38.  
  39.  
  40. Slice1: dd 0    ; Pointers to vectors to the four gush slices
  41. Slice2: dd 0    ;  ie, addresses to bounce off to get to gush code
  42. Slice3: dd 0    ;  (I couldn't figure out a simpler way to get this to work)
  43. Slice4: dd 0
  44.  
  45.  
  46. ; void display_gush(int x, int y, int rot, char far * gu, char far * xi);
  47. ;   x, y : coordinates (across, down) of top-left 'corner' of planet image
  48. ;   rot : amount by which planet is rotated
  49. ;   gu : address of start of gush data
  50. ;   xi : address of start of xion data
  51.  
  52. ; (nb. I'm sort of working under the assumption that the C compiler is
  53. ;   considerate enough to allocate 'far' and 'huge' arrays on paragraph
  54. ;   boundaries, so that the pointers to them come out as WXYZ:0000.
  55. ;    The manual isn't too lucid on the subject, but, well, nothing's gone
  56. ;   wrong yet.)
  57.  
  58. _display_gush:
  59.     push ax
  60.     push bx
  61.     push cx
  62.     push dx
  63.     push di
  64.     push si
  65.     push bp
  66.     push ds
  67.     push es
  68.  
  69.     mov bp,sp
  70.     mov bx,w[bp+20]             ; bx = int x
  71.     mov cx,w[bp+22]             ; cx = int y
  72.     mov dx,w[bp+24]             ; dx = int rot
  73.  
  74.     mov ax,w[bp+26]             ; ax = gush offset
  75.     inc ax
  76.     mov cs:w[Slice1],ax
  77.     add ax,3
  78.     mov cs:w[Slice2],ax
  79.     add ax,3
  80.     mov cs:w[Slice3],ax
  81.     add ax,3
  82.     mov cs:w[Slice4],ax
  83.     mov ax,w[bp+28]             ; ax = gush segment
  84.     mov cs:w[Slice1+2],ax
  85.     mov cs:w[Slice2+2],ax
  86.     mov cs:w[Slice3+2],ax
  87.     mov cs:w[Slice4+2],ax       ; set up pointers to vectors to gush slices (!)
  88.  
  89.     push VID_SEG
  90.     pop es
  91.     mov di,bx
  92.     shr di,1
  93.     shr di,1
  94.     add di,_HiddenPageOffs      ; WARNING! ds has got to be valid here
  95.     mov ax,cx                   ;    (a bug just waiting to happen)
  96.     mov cl,SCR_WIDTH/4
  97.     mul cl
  98.     add di,ax                   ; es:di points to top left of image
  99.  
  100.     mov ax,w[bp+32]
  101.     mov ds,ax
  102.     mov si,w[bp+30]             ; (Possible bug - this value always zero?)
  103.     add si,dx                   ; ds:si points to start of rotated xion
  104.  
  105.     cld
  106.     mov dx,SEQU_ADDR
  107.     and bl,3                    ; choose how to align slices based on
  108.     jnz dis05                   ;  two lowest order bits of x coordinate
  109.     jmp dis00
  110. dis05:
  111.     dec bl
  112.     jz dis01
  113.     dec bl
  114.     jz dis02
  115.  
  116. dis03:                          ; align image to plane 3
  117.     mov bx,di
  118.     mov ax,00802h
  119.     out dx,ax
  120.     call cs:d[Slice1]
  121.  
  122.     inc bx
  123.     mov di,bx
  124.     mov ax,00102h
  125.     out dx,ax
  126.     call cs:d[Slice2]
  127.  
  128.     mov di,bx
  129.     mov ax,00202h
  130.     out dx,ax
  131.     call cs:d[Slice3]
  132.  
  133.     mov di,bx
  134.     mov ax,00402h
  135.     out dx,ax
  136.     call cs:d[Slice4]
  137.     jmp dis04
  138.  
  139. dis02:                          ; align image to plane 2
  140.     mov bx,di
  141.     mov ax,00402h
  142.     out dx,ax
  143.     call cs:d[Slice1]
  144.  
  145.     mov di,bx
  146.     mov ax,00802h
  147.     out dx,ax
  148.     call cs:d[Slice2]
  149.  
  150.     inc bx
  151.     mov di,bx
  152.     mov ax,00102h
  153.     out dx,ax
  154.     call cs:d[Slice3]
  155.  
  156.     mov di,bx
  157.     mov ax,00202h
  158.     out dx,ax
  159.     call cs:d[Slice4]
  160.     jmp dis04
  161.  
  162. dis01:                          ; align image to plane 1
  163.     mov bx,di
  164.     mov ax,00202h
  165.     out dx,ax
  166.     call cs:d[Slice1]
  167.  
  168.     mov di,bx
  169.     mov ax,00402h
  170.     out dx,ax
  171.     call cs:d[Slice2]
  172.  
  173.     mov di,bx
  174.     mov ax,00802h
  175.     out dx,ax
  176.     call cs:d[Slice3]
  177.  
  178.     inc bx
  179.     mov di,bx
  180.     mov ax,00102h
  181.     out dx,ax
  182.     call cs:d[Slice4]
  183.     jmp dis04
  184.  
  185. dis00:                          ; align image to plane 0
  186.     mov bx,di
  187.     mov ax,00102h
  188.     out dx,ax
  189.     call cs:d[Slice1]
  190.  
  191.     mov di,bx
  192.     mov ax,00202h
  193.     out dx,ax
  194.     call cs:d[Slice2]
  195.  
  196.     mov di,bx
  197.     mov ax,00402h
  198.     out dx,ax
  199.     call cs:d[Slice3]
  200.  
  201.     mov di,bx
  202.     mov ax,00802h
  203.     out dx,ax
  204.     call cs:d[Slice4]
  205.  
  206. dis04:                          ; and finish
  207.     pop es
  208.     pop ds
  209.     pop bp
  210.     pop si
  211.     pop di
  212.     pop dx
  213.     pop cx
  214.     pop bx
  215.     pop ax
  216.     ret
  217.  
  218.  
  219. _Text ENDS
  220.  
  221.